package com.management.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MybatisPlusAutoFill implements MetaObjectHandler {
    /**
     * 向数据库表中插入数据时，自动填充
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        LocalDateTime time = LocalDateTime.now();
        this.fillStrategy(metaObject,"createTime",time);
        this.fillStrategy(metaObject,"modifyTime",time);

    }

    /**
     * 修改数据库表中记录时，自动填充
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        LocalDateTime time = LocalDateTime.now();
        this.fillStrategy(metaObject, "modifyTime", time);
    }
}
